package cn.edu.scau.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.scau.dao.RecoveryTrackMapper;
import cn.edu.scau.entity.RecoveryTrack;
import cn.edu.scau.service.RecoveryTrackService;

@Service
public class RecoveryTrackServiceImpl implements RecoveryTrackService{
	@Autowired
	RecoveryTrackMapper recoveryTrackMapper;
	
	//@Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED,rollbackFor = RuntimeException.class)
	
	@Override
	public boolean insert(RecoveryTrack recoveryTrack) {
		int line = recoveryTrackMapper.insertSelective(recoveryTrack);
        if(1==line)
        {
            return true;
        }
        return false;
	}

	@Override
	public boolean update(RecoveryTrack recoveryTrack) {
		int line = recoveryTrackMapper.updateByPrimaryKeySelective(recoveryTrack);
        return line ==1? true:false;
	}

	@Override
	public boolean delete(Date recoverytrackdate, Integer recoveryregisterid) {
		int line = recoveryTrackMapper.deleteByPrimaryKey(recoverytrackdate,recoveryregisterid);
        return line ==1? true:false;
	}

	@Override
	public RecoveryTrack selectByPrimaryKey(Date recoverytrackdate, Integer recoveryregisterid) {
		return recoveryTrackMapper.selectByPrimaryKey(recoverytrackdate,recoveryregisterid);
	}

	@Override
	public List<RecoveryTrack> selectByRecoveryRegisterID(Integer recoveryregisterid) {
		return recoveryTrackMapper.selectByRecoveryRegisterID(recoveryregisterid);
	}

	@Override
	public List<RecoveryTrack> selectAll() {
		return recoveryTrackMapper.selectAll();
	}

	@Override
	public List<RecoveryTrack> find(Date recoverytrackdate, Integer recoveryregisterid, String customername) {
		if(recoverytrackdate!=null&&StringUtils.isBlank(recoverytrackdate.toString())){
			recoverytrackdate=null;
        }
		if(recoveryregisterid!=null&&recoveryregisterid<1){
    		recoveryregisterid=null;
        }
        if(StringUtils.isBlank(customername)){
        	customername=null;
        }
		return recoveryTrackMapper.find(recoverytrackdate, recoveryregisterid, customername);
	}

	@Override
	public List<RecoveryTrack> selectWithNurseID(Integer nurseID) {
		if(nurseID!=null&&nurseID<1){
			return null;
        }
		return recoveryTrackMapper.selectWithNurseID(nurseID);
	}

	@Override
	public List<RecoveryTrack> findWithNurseID(Date recoveryTrackDate,Integer recoveryRegisterID,String customerName,Integer nurseID) {
		if(nurseID!=null&&nurseID<1){
			return null;
        }
		if(recoveryTrackDate!=null&&StringUtils.isBlank(recoveryTrackDate.toString())){
			recoveryTrackDate=null;
        }
		if(recoveryRegisterID!=null&&recoveryRegisterID<1){
			recoveryRegisterID=null;
        }
        if(StringUtils.isBlank(customerName)){
        	customerName=null;
        }
		return recoveryTrackMapper.findWithNurseID(recoveryTrackDate, recoveryRegisterID, customerName, nurseID);
	}
}
